package com.xin.utils;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import com.xin.entity.crm.easypoi.ExcelVerifyInfo;
import com.xin.exception.MyException;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
 * excel工具类
 */
public class ExcelUtils {

    /**
     * 导出数据
     * @param list
     * @param response
     * @param <T>
     */
    public static <T> void exportData(List<T> list, HttpServletResponse response,Class<?> entityClass) throws IOException {
        // 返回excel给前端
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-Disposition","attachment;filename=excel.xlsx");
        ExportParams params = new ExportParams();
        params.setTitle("蓉宝购");
        params.setSheetName("员工信息");
        Workbook sheets = ExcelExportUtil.exportExcel(params, entityClass, list);
        sheets.write(response.getOutputStream());
    }

    /**
     * 导入数据
     * @param response
     * @param inputStream
     * @param <T>
     * @return
     */
    public static <T> List<T> importData(FileInputStream inputStream,HttpServletResponse response,Class entityClass){
        ImportParams params = new ImportParams();
        params.setHeadRows(1);
        params.setNeedVerify(true);
        return null;
    }
    /**
     * 获取工作簿
     * @param inputStream
     * @return
     */
    public static Workbook getWorkBook(FileInputStream inputStream){
        return null;
    }
}
